#ifndef LONGKEY_CRASH_IF_SPECIFIC_ERROR_H_
#define LONGKEY_CRASH_IF_SPECIFIC_ERROR_H_

#include <Windows.h>

#if defined __cplusplus

extern HRESULT g_crash_specific_error;
extern void CrashIfSpecificError(HRESULT hr);

#define CRASH_IF_SPECIFIC_ERROR(hr) CrashIfSpecificError(hr)

inline bool CheckSuccessWithSpecificError(HRESULT hr) {
	CRASH_IF_SPECIFIC_ERROR(hr);
	return hr >= 0;
}

inline bool CheckFailureWithSpecificError(HRESULT hr) {
	CRASH_IF_SPECIFIC_ERROR(hr);
	return hr < 0;
}

#ifdef SUCCEEDED
#undef SUCCEEDED
#endif
#define SUCCEEDED(hr) CheckSuccessWithSpecificError(hr)

#ifdef FAILED
#undef FAILED
#endif
#define FAILED(hr) CheckFailureWithSpecificError(hr)

#else   // defined __cplusplus

#define CRASH_IF_SPECIFIC_ERROR(hr)

#endif  // defined __cplusplus

#endif	// LONGKEY_CRASH_IF_SPECIFIC_ERROR_H_